package io.framework.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.framework.common.constant.Constant;
import io.framework.common.page.PageData;
import io.framework.common.service.impl.CrudServiceImpl;
import io.framework.common.utils.ConvertUtils;
import io.framework.modules.sys.dao.SysAddressListDao;
import io.framework.modules.sys.dto.SysAddressListDTO;
import io.framework.modules.sys.entity.SysAddressListEntity;
import io.framework.modules.sys.service.SysAddressListService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 通讯录
 *
 * @author Gujq email
 * @since 1.0.0 2020-04-14
 */
@Service
public class SysAddressListServiceImpl extends CrudServiceImpl<SysAddressListDao, SysAddressListEntity, SysAddressListDTO> implements SysAddressListService {

    @Override
    public QueryWrapper<SysAddressListEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");

        QueryWrapper<SysAddressListEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(id), "id", id);

        return wrapper;
    }

    @Override
    public PageData<SysAddressListDTO> page(Map<String, Object> params){
        //转换成like
        paramsToLike(params, "username");

        //分页
        IPage<SysAddressListEntity> page = getPage(params, Constant.CREATE_DATE, false);

        //查询
        List<SysAddressListEntity> list = baseDao.getList(params);

        return getPageData(list, page.getTotal(), SysAddressListDTO.class);
    }

    @Override
    public List<SysAddressListDTO> lists(Map<String, Object> params){
        //转换成like
        paramsToLike(params, "username");

        //查询
        List<SysAddressListEntity> list = baseDao.getList(params);

        return ConvertUtils.sourceToTarget(list, SysAddressListDTO.class);
    }

}